<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>会员页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../../res/js/jquery-3.4.1.js"></script>
</head>
<body>

会员id：
<div class="layui-inline">
    <input class="layui-input" id="memberAccout" name="memberAccout"  width="100" height="40">
</div>
<button class="layui-btn" onclick="query()">搜索</button>


<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">




    <div class="layui-btn-container">

        <button class="layui-btn layui-btn-sm" lay-event="insertRec">添加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>



<script src="../../../res/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->





<script>
    var openIndex = null;
    layui.use(['table','layer'], function(){
        var table = layui.table;
        var $ = layui.$;
        var layer = layui.layer;

        table.render({

            elem: '#test'
            ,url: '../../../immMember/findAll'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '用户数据表'
            ,cols: [[
                ,{field: 'memberId', title: '会员id', width:90, fixed: 'left'}
                ,{field: 'discount', title: '会员折扣', width:80}
                ,{field: 'memberAccout', title: '会员账号', width:90}
                ,{field: 'memberPassword', title: '会员密码', width:120}
                ,{field: 'memberPhone', title: '电话', width: 90}
                ,{field: 'sex', title: '性别', width: 90}
                ,{field: 'createTime', title: '注册时间', width: 90}
                ,{field: 'state', title: '是否有效', width:100}
                ,{field: 'operator', title: '操作人', width: 90}
                ,{field: 'sort', title: '排序', width: 89}
                ,{field: 'remark2', title: '备注', width: 170}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
            ,id: 'testReload'
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){

                case 'insertRec':
                    openIndex = layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['50%', '80%'], //宽高
                        content: 'zjmember.html',
                        end:function () {

                            // layer.msg("就这！");
                        },

                    });
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行吗?', function(index){
                    var url = "../../../immMember/deleteById";
                    var datas = {memberId:data.memberId};
                    $.post(url,datas,function (objs) {
                        if (objs.state > 0){
                            console.log(objs.msg);
                            layer.close(index);
                            table.reload('test'); //刷新表格

                        }
                    },"json")
                });
            } else if(obj.event === 'edit'){
                var sid=data.memberId;
                console.info(sid);
                perUser = data;
                onclose = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['50%', '80%'], //宽高
                    content: 'zjmember.html?memberId='+sid,
                    end:function () {

                    }
                });
            }
        });

    });

    function closeOpen(msg) {
        layer.close(openIndex);
        layer.msg(msg,{time:1000},function () {
            table.reload("test");
        })
    }

    function query() {
        table.reload('testReload',{
            where:{
                memberAccout:$("#memberAccout").val(),
            },
            page:{
                curr:1
            }
        })
    }

</script>

</body>
</html>
